<template lang="html">
  <div>
    <div class="search">
        <div class="input">
            <p>
				<label>工单状态:</label>
				<el-select placeholder="请输入内容" v-model="orderStatus">
						<el-option value="">请选择</el-option>
						<el-option
							v-for="(item,key) in orderList"
							:key="key"
							:label="item.label"
							:value="item.value"
						></el-option>
				</el-select>
			</p>
            <!-- <p><label>来源名称：</label><el-input placeholder="请输入编码" label="条件"></el-input></p>
            <p><label>来源编码：</label><el-input placeholder="请输入编码" label="条件"></el-input></p>
            <p><label>来源ID：</label><el-input placeholder="请输入编码" label="条件"></el-input></p> -->
            <p><el-button type="primary" class="se" @click="searchOrder()" style="margin-left:10px;">搜索</el-button></p>
        </div>
    </div>
    <!-- <div class="add">
       <el-button type="primary" @click="add">新增</el-button>
    </div> -->
    <tableVue :list="list" :state="false" @sizeChange="handleSize" :total="total" v-loading="loading">
        <slot>
          <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  @click="handleEdit(scope.row)">详情
                </el-button>
                <el-button
                  v-if="scope.row.workerOrderStatus=='待处理'"
                  size="mini"
                  type="primary"
                  class="del"
                  @click="handlOrder(scope.row)">处理</el-button>
                <!-- <el-button
                  size="mini"
                  type="danger"
                  class="del"
                  @click="del(scope.row)">删除</el-button>-->
              </template>
          </el-table-column>
        </slot>
    </tableVue>
    <dialogVue title="处理工单" :dialog="dialog" @close="changeData" :state="false">
        <slot>
            <el-form :model="pageData" ref="ruleForm" label-width="120px" class="demo-ruleForm">
				<el-form-item label="系统评估师价格:">
					<el-input v-model="pageData.amount" placeholder="请输入评估价格" disabled></el-input>
				</el-form-item>
				<el-form-item label="评估师价格:">
					<el-input v-model="pageData.evaluation" placeholder="请输入评估价格"></el-input>
				</el-form-item>
				<el-form-item label="鉴定结果:">
					<el-input v-model="pageData.workResult" placeholder="请输入鉴定结果"></el-input>
				</el-form-item>
                <el-form-item v-if="showPhone" label="实物拍照:" >
					 <el-upload
                          class="upload-demo"
                          ref="upload"
                          :action="uploadingImg"
                          :on-change="changeImgFile"
                          :file-list="fileList"
                          list-type="picture"
                          :auto-upload="false">
                          <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                    </el-upload>
				</el-form-item>
                <el-form-item label="寄卖方式:">
                    <el-select v-model="pageData.consignType" placeholder="请选择" disabled>
                        <el-option value="">请选择</el-option>
                        <el-option
                        v-for="(item,key) in appraiserList"
                        :key="key"
                        :label="item.label"
                        :value="item.value">
                        </el-option>
                  </el-select>
              	</el-form-item>
				<el-form-item class="confirm">
					<el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
				</el-form-item>
            </el-form>
        </slot>
    </dialogVue>
  </div>
</template>

<script>
import { Base64 } from 'js-base64';
import Data from './index.js'
import dialogVue from '@/components/dialog.vue'
import tableVue from '@/components/alltable.vue'
import {
  appraiserAdminList,
  getAppraiserLists,
  delWorkOrder,
  getWorkOrderDetail,
  kdjmOrderList,
  subOrderForm
} from "@/api/appraiserAdmin/appraiserAdmin";
export default {
  components : {
    tableVue,
    dialogVue
  },
   data () {
		return JSON.parse(JSON.stringify(Data))
   },
   mounted () {
		this.getAppraiserAdminList();
   },
   methods : {
     getAppraiserAdminList (data) {
       kdjmOrderList(data).then(res=>{
		   this.total = res.data.data.total;
		   this.loading =false;
           this.list.tbody = res.data.data.records.map(item=>{
               switch(item.consignType){
                        case "MEN_DIAN":
                            item.consignType = "去门店";
                            break
                        case "SHANG_MEN":
                            item.consignType = "上门";
                            break
                        case "KUAIDI":
                            item.consignType = "快递";
                            break
                        case "PREV_MEN_DIAN":
                            item.consignType = "门店预约";
                            break
                        case "PREV_PIC":
                            item.consignType = "图片估价";
                            break
                        default:
                            break;
                }
                switch(item.workerOrderStatus){
                        case "VIST":
                            item.workerOrderStatus = "待上门";
                            break
                        case "WAIT":
                            item.workerOrderStatus = "待处理";
                            break
                        case "COMPLETE":
                            item.workerOrderStatus = "评估完成";
                            break
                        case "SEND":
                            item.workerOrderStatus = "待发货";
                            break
                        case "SHIPPED":
                            item.workerOrderStatus = "已发货";
                            break
                        case "RETURNED":
                            item.workerOrderStatus = "待退货";
                            break
                        case "BACK":
                            item.workerOrderStatus = "发退货";
                            break
                        case "STORAGE":
                            item.workerOrderStatus = "待入库";
                            break
                        case "ESTIMATE":
                            item.workerOrderStatus = "图片评估完成";
                            break
                        case "CANCAL":
                            item.workerOrderStatus = "已取消";
                            break
                        case "FINISH":
                            item.workerOrderStatus = "已完成";
                            break
                        default:
                            break;
                }
               item.gmtCreate = this.switchTime(item.gmtCreate)
               item.gmtUpdate = this.switchTime(item.gmtUpdate)
               this.pageData.consignType = item.consignType;


               return item;
           });
       })
     },
     changeImgFile (file) {
          let reader = new FileReader();
          reader.readAsDataURL(file.raw);
          reader.onload = () => {
                this.pageData.productPicture.push(reader.result.split(',')[1]);
          }
    },
	 handleSize(size){
		  let data ={
			 workerOrderStatus:this.orderStatus,
			 current:size,
			 size:10
		 }
		 this.getAppraiserAdminList(data)
	 },
     changeData (data) {
       this.dialog = data;
     },
	 del(data){ //删除工单
	 	this.delMessage(()=>{
			 delWorkOrder(data.workOrderId).then(res=>{
				 if(res.rows.code =="OK"){
					this.$message.success('删除成功');
					this.getAppraiserAdminList();
				 }else{
					this.$message.error(res.data.message);
				 }
			 })
		 })
     },
     handlOrder(data){ //处理工单
       console.log(data);
     this.pageData.productPicture=[];
        switch(data.consignType){
                        case "去门店":
                            this.pageData.consignType = "MEN_DIAN";
                            break
                        case "上门":
                            this.pageData.consignType = "SHANG_MEN";
                            break
                        case "快递":
                            this.pageData.consignType = "KUAIDI";
                            break
                        case "门店预约":
                            this.pageData.consignType = "PREV_MEN_DIAN";
                            break
                        case "图片估价":
                            this.pageData.consignType = "PREV_PIC";
                            break
                        default:
                            break;
            }
        if (data.consignType == '图片估价') {
           this.pageData.amount = data.consignMaxPrice;

        } else {
          this.pageData.amount = data.evaluationAmount;
        }
        this.dialog = true;
        if(data.consignType =="图片估价"){

            this.showPhone = false;
        }
        this.pageData.workOrderId = data.workOrderId
        this.pageData.uuid = data.orderNo

        this.fileList=[];
     },
     submitForm(){
        this.pageData.productPicture = this.pageData.productPicture.join(",");
        subOrderForm(this.pageData,"PUT").then(res=>{
            this.pageData.productPicture = [];
            if(res.data.code=="OK"){
                 this.dialog = false;
                 this.$message.success('处理成功');
                 this.getAppraiserAdminList()
            }else{
                this.$message.error(res.data.message)
            }
        })
     },
	 handleEdit(data){
		 this.$router.push({path:'/appraiser/myorder/orderDetails',query:{id:data.workOrderId,key:'luxuryWorkOrder'}})
	 },
	 searchOrder(){
		 let data ={
			 workerOrderStatus:this.orderStatus
		 }
		 this.getAppraiserAdminList(data)
	 }
   }
}
</script>

<style scoped>
  @import "../../../../styles/common.css";
</style>
